<?php
/**
 * Created by PhpStorm.
 * User: wodrow
 * Date: 18-7-30
 * Time: 上午10:55
 */

namespace common\components\tools;

/**
 * @desc https://www.jb51.net/article/132970.htm
 * Class Image
 * @package common\components\tools
 */
class Image
{
    /**
     * @param $dist_path
     * @param array $options imagefttext($dst, 13, 0, 20, 20, $black, $font, '快乐编程'); //输出图片
     */
    public static function addTextWater($dist_path, $save_path, $text = '')
    {
        ini_set("gd.jpeg_ignore_warning", 1);
        $dst = @imagecreatefromstring(file_get_contents($dist_path)); //打上文字
        $font = \Yii::getAlias('@data/fonts/ztgjkt.ttf'); //字体
        $black = imagecolorallocate($dst, 0xff, 0x00, 0x00); //字体颜色
        imagefttext($dst, 130, 0, 0, 200, $black, $font, $text.'特殊订单'); //输出图片
        list($dst_w, $dst_h, $dst_type) = getimagesize($dist_path);
        switch ($dst_type) {
            case 1://GIF
                imagegif($dst, $save_path);
                break;
            case 2://JPG
                imagejpeg($dst, $save_path);
                break;
            case 3://PNG
                imagepng($dst, $save_path);
                break;
            default:
                break;
        }
        imagedestroy($dst);
    }
}